/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-16 17:51:45
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-18 06:45:47
 */
import 'package:flutter/material.dart';
import 'package:flutter_data_center/model/camera/camera_model.dart';

import 'camera_item.dart';

class CameraGroup extends StatefulWidget {
  const CameraGroup({Key key, this.camera, this.index}) : super(key: key);
  final CameraItemModel camera;
  final int index;

  @override
  _CameraGroupState createState() => _CameraGroupState();
}

class _CameraGroupState extends State<CameraGroup> {
  final keyWidget = GlobalKey();
  Size size;
  void calculateSizeAndPosition() =>
      WidgetsBinding.instance.addPostFrameCallback((_) {
        final RenderBox box =
            keyWidget.currentContext.findRenderObject(); // 包含widget的绘制信息
        setState(() {
          size = box.size;
        });
        // print(size.height);
        // TODO 获得高度，保存高度  然后通过列表数据， 记录每个大楼层的高度，并存于一个map中 每次滑动都检测
      });
  @override
  void initState() {
    super.initState();
    calculateSizeAndPosition();
  }

  @override
  Widget build(BuildContext context) => Column(
        children: [
          ListTile(
            key: keyWidget,
            title: Row(
              children: [
                Container(
                  height: 20,
                  width: 5,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(5),
                    color: Theme.of(context).primaryColor,
                  ),
                ),
                SizedBox(
                  width: 20,
                ),
                Text('${widget.index} 号楼'),
              ],
            ),
          ),
          ...List.generate(
              5,
              (index) => CameraItem(
                    camera: widget.camera,
                    pIndex: widget.index,
                    index: index,
                  ))
        ],
      );
}
